package com.kust.smarthome.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kust.smarthome.web.mapper.LampMapper;
import com.kust.smarthome.web.model.DeviceState;
import com.kust.smarthome.web.model.Lamp;
import com.kust.smarthome.web.service.ILampService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author iAuzre
 * @since 2021-06-28
 */
@Service
public class LampServiceImpl extends ServiceImpl<LampMapper, Lamp> implements ILampService {

    @Resource
    private LampMapper lampMapper;

    @Override
    public int insert(Lamp lamp) {
        return lampMapper.insert(lamp);
    }

    @Override
    public List<Lamp> getByUserId(Integer userId) {
        QueryWrapper<Lamp> query = new QueryWrapper<>();
        query.eq("user_id",userId);
        return lampMapper.selectList(query);
    }

    @Override
    public List<DeviceState> findOperationList(Integer deviceId, Integer typeId) {
        return lampMapper.getOperationList(deviceId,typeId);

    }

    @Override
    public boolean setupdate(Integer id) {
        lampMapper.changeUpdate(id);
        return true;
    }

}
